<template>
    <div style="display: flex;line-height: 60px;">
        <div style="cursor: pointer;">
            <i :class="icon" style="font-size: 25px" @click="collapse"></i>
        </div>
        <div style="flex: 1px;text-align: center;font-size: 34px;" >
            <span>鼎盛物流管理系统</span>
        </div>
        <span>{{user.name}}</span>
        <el-dropdown>
            <i class="el-icon-user" style="margin-left:5px;margin-top: 18px;"></i>
            <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="toUser">编辑个人资料</el-dropdown-item>
                <el-dropdown-item @click.native="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
        </el-dropdown>
        <el-dialog
                title="提示"
                :visible.sync="centerDialogVisible"
                width="30%"
                center>
            <span>是否确认退出登录</span>
            <span slot="footer" class="dialog-footer">
                <el-button @click="centerDialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="logout">确 定</el-button>
              </span>
        </el-dialog>
    </div>
</template>

<script>
    export default {
        // eslint-disable-next-line vue/multi-word-component-names
        name: "Header",
        props:{
          icon:String
        },
        data() {
            return {
                centerDialogVisible: false,
                user:JSON.parse(sessionStorage.getItem('CurUser'))
            }
        },
        methods:{
            toUser(){
                console.log(window.sessionStorage.getItem("CurUser"))
                // this.$router.push("/Home")
            },
            logout(){
                this.$confirm('您确定退出登录吗？','提示',{
                        confirmButtonText:'确定',
                        type:'warning',
                        center:true,    //文字剧中
                    }
                ).then(()=>{
                    console.log("退出登录")
                    this.$message({
                        type:"success",
                        message:'退出登录成功'
                    })
                    this.$router.push("/login")
                    //情况sessionStorage
                    sessionStorage.clear()
                }).catch(()=>{
                    console.log("退出登录")
                    this.$message({
                        type:"info",
                        message:'已取消退出登录'
                    })
                })
            },
            collapse(){
                this.$emit('doCollapse')
            }
        },
        created() {
            this.$router.push("/Home")
        }
    }
</script>

<style scoped>

</style>